import type { MaProTableColumns, MaProTableExpose } from '@mineadmin/pro-table'
import type { UseDialogExpose } from '@/hooks/useDialog.ts'
import { useMessage } from '@/hooks/useMessage.ts'
import { deleteByIds, resetPassword } from '~/base/api/user.ts'
import { ResultCode } from '@/utils/ResultCode.ts'
import MaUploadImage from "@/components/ma-upload-image/index.vue";

export default function getTableColumns(dialog: UseDialogExpose, formRef: any, t: any): MaProTableColumns[] {
  const msg = useMessage()
  return [

    // 多选列
    { type: 'selection', showOverflowTooltip: false},
    // 排序列
    { width: '80px', type: 'sort' },
    // 索引序号列
    // { type: 'index' },
    // 普通列
    { label: '分类ID', prop: 'id' },
    { label: '分类名称', prop: 'xxxx',
      width: '250px',
      cellRender: ({ row }) => (
        <el-input v-model={row.name} />
      )
    },
    { label: '分类图片', prop: 'xxx',
      cellRender: ({ row }) => (
        <MaUploadImage size="150 150" v-model={row.xxx} />
      ),
    },
    { label:'推荐', prop: 'xxx',
      cellRender: ({ row }) => (
        <el-switch v-model={row.hot} active-value={1} inactive-value={0} />
      ),
    },
    { label:'状态', prop: 'xxx',
      cellRender: ({ row }) => (
        <el-switch v-model={row.state} active-value={1} inactive-value={0} />
      ),
    },
    // 操作列
    {
      type: 'operation',
      label:'操作',
      fixed: 'right',
      width: '320px',
      operationConfigure: {
        type: 'tile',
        actions: [
          {
            name: 'edit',
            icon: 'material-symbols:person-edit',
            text: '编辑',
            onClick: ({ row }) => {
              dialog.setTitle('编辑')
              dialog.open({ formType: 'edit', data: row })
            },
          },
          {
            name: 'del',
            icon: 'mdi:delete',
            text: '删除',
            onClick: ({ row }, proxy: MaProTableExpose) => {
              msg.delConfirm(t('crud.delDataMessage')).then(async () => {
                const response = await deleteByIds([row.id])
                if (response.code === ResultCode.SUCCESS) {
                  msg.success(t('crud.delSuccess'))
                  proxy.refresh()
                }
              })
            },
          },
          {
            name: 'add',
            text: '添加下级',
            onClick: ({ row }) => {
              dialog.setTitle('添加下级')
              dialog.open({ formType: 'add', data: row })
            },
          },
          {
            name: 'copy',
            text: '复制链接',
            onClick: ({ row }) => {},
          },
          {
            name: 'menu',
            text: '目录商品',
          }
        ],
      },
    },
  ]
}
